﻿using System;
using System.Collections.Generic;
using System.Web;

namespace IXION.BLOG.COMMON.DATE
{
    /// <summary>
    /// 时间工具
    /// </summary>
    public class DateUtils
    {
        /// <summary>
        /// 根据时间字符串返回当天的0点
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        public static DateTime GetDayBegin(string day) {
            string[] infos = day.Split(new char[] { '-' });
            DateTime date = new DateTime(int.Parse(infos[0]), int.Parse(infos[1]), int.Parse(infos[2]));
            return date;
        }
        /// <summary>
        /// 根据时间字符串返回次日的0点
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        public static DateTime GetDayEnd(string day)
        {
            return GetDayBegin(day).AddDays(1);
        }
        /// <summary>
        /// 计算当天到目标日期的天数
        /// </summary>
        /// <param name="date"></param>
        /// <returns>剩余天数 0表示当天 小于0表示时间已过 用于倒计时功能</returns>
        public static int LeftDays(DateTime date) {
            return (int)date.Subtract(DateTime.Now).TotalDays;
        }
    }
}